package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyJtgz;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyJtgzMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyJtgzParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyJtgzResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtyJtgzService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-02-17
 */
@Service
public class BtyJtgzServiceImpl extends ServiceImpl<BtyJtgzMapper, BtyJtgz> implements BtyJtgzService {

    @Override
    public void add(BtyJtgzParam param){
        BtyJtgz entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyJtgzParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyJtgzParam param){
        BtyJtgz oldEntity = getOldEntity(param);
        BtyJtgz newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyJtgzResult findBySpec(BtyJtgzParam param){
        return null;
    }

    @Override
    public List<BtyJtgzResult> findListBySpec(BtyJtgzParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyJtgzParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public boolean insertJtgz(List<BtyJtgz> list) {
        return baseMapper.insertJtgz(list);
    }

    @Override
    public List<BtyJtgzResult> jtgzList() {
        return baseMapper.jtgzList();
    }

    @Override
    public List<BtyJtgzResult> customList(BtyJtgzParam param) {
        return baseMapper.customList(param);
    }

    private Serializable getKey(BtyJtgzParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyJtgz getOldEntity(BtyJtgzParam param) {
        return this.getById(getKey(param));
    }

    private BtyJtgz getEntity(BtyJtgzParam param) {
        BtyJtgz entity = new BtyJtgz();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
